<html>
<script>

var input = "![image3.png](https://upload-images.jianshu.io/upload_images/2085791-4d8b2cda3a057fb6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)" + "\n" + 

"![image1.png](https://upload-images.jianshu.io/upload_images/2085791-9aa6232b1426df28.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)" + "\n" + 

"![image2.png](https://upload-images.jianshu.io/upload_images/2085791-04f2773c126194fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)";

var IMAGE_PATTERN = /^!\[(.*)\]\((.*)\)$/;
var IMAGE_INDEX = /^image(\d+).*$/;

function MyImage(index, name, url){
	this.index = index;
	this.name = name;
	this.url = url;
}

var imagePool = [];


function sortByIndex(v1,v2){
		if(v1.index < v2.index ){
			return -1;
		}
		else if(v1.index > v2.index ){
			return 1;
		}
		else return 0;
}


function getParsedImage(input) {

	if (input.indexOf("https://upload-images.jianshu.io") < 0 ) {
		return;
	} 
	
	var result = IMAGE_PATTERN.exec(input);
	if( result.length != 3){
		return;
	}

	var imageIndex = IMAGE_INDEX.exec(result[1]);
	console.assert(imageIndex.length === 2);
	return new MyImage(imageIndex[1], result[1], result[2]);
}
			
var raw = input.split("\n");

for( var i = 0; i < raw.length; i++){
	var each = getParsedImage(raw[i]);
	if( !!each){
		imagePool.push(each);
	}
}

imagePool.sort(sortByIndex);
debugger;

</script>
</html>